import numpy as np
import sys
import os

# 导入原函数
sys.path.insert(0, os.path.dirname(__file__))
from final2 import *

# 使用上面的函数加载数据
data = load_data('data.txt')
# 使用calculate_all_tangent_lines函数计算交点
intersection_points = calculate_all_tangent_lines(data, 1)

# 分割为外圈和内圈
outside_points = [intersection_points[i] for i in range(1, len(intersection_points), 2)]
inside_points = [intersection_points[i] for i in range(0, len(intersection_points), 2)]

# 过滤距离原始点小于radius的点
filtered_outside_points, out_duo = filter_points_near_centers(outside_points, data, 1)
filtered_inside_points, in_duo = filter_points_near_centers(inside_points, data, 1)

# 计算原始点之间的平均距离，用作补点的密度
distances = [np.linalg.norm(np.array(data[i+1]) - np.array(data[i])) for i in range(len(data) - 1)]
average_distance = np.mean(distances)

# 对过滤后的外圈和内圈进行补点
supplemented_outside_points = add_inbetween_points(filtered_outside_points, average_distance)
supplemented_inside_points = add_inbetween_points(filtered_inside_points, average_distance)

# 保存结果
with open('python_outside_points.txt', 'w') as f:
    for point in supplemented_outside_points:
        f.write(f"{point[0]},{point[1]}\n")

with open('python_inside_points.txt', 'w') as f:
    for point in supplemented_inside_points:
        f.write(f"{point[0]},{point[1]}\n")

with open('python_original_points.txt', 'w') as f:
    for point in data:
        f.write(f"{point[0]},{point[1]}\n")

print(f"Python results saved:")
print(f"  Inside points: {len(supplemented_inside_points)}")
print(f"  Outside points: {len(supplemented_outside_points)}")
print(f"  Average distance: {average_distance}")

